package com.kmust.dream.wanderingdream.product.controller;

import com.kmust.dream.wanderingdream.comm.pojo.ResultBean;
import com.kmust.dream.wanderingdream.product.entity.ProductSku;
import com.kmust.dream.wanderingdream.product.service.ProductSkuService;
import com.kmust.dream.wanderingdream.product.vo.GetSkuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product/productSku")
@Api(value = "获取sku")
public class ProductSkuController {

    @Autowired
    private ProductSkuService productSkuService;

    @ApiOperation(value = "获取全部的sku", notes = "无参数")
    @GetMapping("/getAllSku")
    public ResultBean getAllSku() {
        return productSkuService.getAllSku();
    }

    @ApiOperation(value = "添加sku", notes = "参数是sku json对象")
    @PostMapping("/addSku")
    public ResultBean addSku(@RequestBody ProductSku productSku) {
        return productSkuService.addSku(productSku);
    }

    @ApiOperation(value = "更新sku", notes = "参数是sku json对象")
    @PutMapping("/updateSku")
    public ResultBean updateSku(@RequestBody ProductSku productSku) {
        return productSkuService.updateSku(productSku);
    }

    @ApiOperation(value = "删除sku", notes = "参数是sku的主键")
    @DeleteMapping("/deleteSku/{skuId}")
    public ResultBean deleteSku(@PathVariable Integer skuId) {
        return productSkuService.deleteSku(skuId);
    }

    @ApiOperation(value = "获取sku的版本", notes = "参数是sku的主键")
    @GetMapping("/getSkuVersion/{skuId}")
    public ResultBean getSkuVersion(@PathVariable Integer skuId) {
        return productSkuService.getSkuVersion(skuId);
    }

    @ApiOperation(value = "获取指定的sku", notes = "参数是getSkuVO的json字符串")
    @PostMapping("/getSku")
    public ResultBean getSku(@RequestBody GetSkuVO getSkuVO) {
        return productSkuService.getSku(getSkuVO);
    }

    @GetMapping("/getSkuById/{skuId}")
    public ResultBean getSkuById(@PathVariable Integer skuId) {
        return productSkuService.getSkuById(skuId);
    }

    @GetMapping("/getSkuStock/{skuId}")
    public ResultBean getSkuStock(@PathVariable Integer skuId) {
        return productSkuService.getSkuStock(skuId);
    }

    @ApiOperation(value = "批量获取sku通过productID")
    @GetMapping("/getAllSkuByProductId/{productId}")
    public ResultBean getAllSkuByProductId(@PathVariable Integer productId) {
        return productSkuService.getAllSkuByProductId(productId);
    }
}
